package cn.meebook.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.meebook.domain.DomainBookCircleNumber;
import cn.meebook.domain.Domain;
import cn.meebook.service.BookService;

@Controller
public class HelloController {
	
	@Autowired
	private BookService bookService;
	
	@RequestMapping(value = "/")
	String home() {
		return "redirect:index.html";
	}
	
	@RequestMapping(value = "/domains", produces = "text/plain; charset=utf-8")
    @ResponseBody
    String domains() {
        String result = "";
        
        List<Domain> domains = bookService.getAllDomains();
        result += domains.get(0).getName() + "：\r\n";
        
        Domain bd = domains.get(0);
        List<DomainBookCircleNumber> bcns = bookService.getBookCircleNumbersInDomain(bd);
        for(DomainBookCircleNumber bcn : bcns) {
        	result += "    " + bcn.toString() + "\r\n";
        }
        
        return result;
    }

}
